package com.weifly.jettycn.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.weifly.jettycn.JettycnUtil;
import com.weifly.jettycn.service.IProjectService;
import com.weifly.jettycn.util.PageInfo;
import com.weifly.jettycn.util.QueryInfo;

/**
 * 主页面
 * 
 * @author wei
 * @date 2011-10-04
 */
@Controller
public class MainLogic implements ApplicationContextAware{
	
	IProjectService projectService;

	public void setProjectService(IProjectService projectService) {
		this.projectService = projectService;
	}

	/**
	 * 主页面
	 */
	@RequestMapping("/main/main.do")
	public ModelAndView main(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		QueryInfo queryInfo = JettycnUtil.createQueryInfo(request);
		queryInfo.setPageCount(20);
		PageInfo pageInfo = projectService.queryProjectList(queryInfo, null);
		request.setAttribute("projectList", pageInfo);
		
		return new ModelAndView("main/main");
	}

	public void setApplicationContext(ApplicationContext appCtx)
			throws BeansException {
		JettycnUtil.appCtx = appCtx;
	}
}
